package org.dsapr.util;

import java.util.Random;

public class ArrayUtil {
	public static void fillRandom(boolean[][] array) {
		Random random = new Random();

		for(int i = 0; i < array.length; ++i) {
			for(int j = 0; j < array[i].length; ++j) {
				array[i][j] = random.nextBoolean();
			}
		}
	}
	// 根据概率填充数组
    public static void fillTrueRandom(boolean[][] array, int probability) {
	    Random random = new Random();
	    for(int i = 0; i < array.length; ++i) {
		    for(int j = 0; j < array[i].length; ++j) {
				// random 0 ~ 9
			    array[i][j] = random.nextInt(10) < probability;
		    }
	    }

		// 滑翔机
//	    array[10][10] = true;
//	    array[10][11] = true;
//	    array[10][12] = true;
//	    array[9][12] = true;
//	    array[8][11] = true;
    }

	// 是否下标越界
	public static boolean isNotOutOfBounds(boolean[][] arr, int x, int y) {
		return !isOutOfBounds(arr, x, y);
	}

	// 是否下标越界
	public static boolean isOutOfBounds(boolean[][] arr, int x, int y) {
		return x < 0 || x >= arr.length || y < 0 || y >= arr[0].length;
	}
}
